package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllFileRevisions", query = "select myFileRevision from FileRevision myFileRevision"),
		@NamedQuery(name = "findFileRevisionByApprovalStatus", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.approvalStatus = ?1"),
		@NamedQuery(name = "findFileRevisionByApprovalStatusContaining", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.approvalStatus like ?1"),
		@NamedQuery(name = "findFileRevisionByApprovedDate", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.approvedDate = ?1"),
		@NamedQuery(name = "findFileRevisionByCreatedDate", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.createdDate = ?1"),
		@NamedQuery(name = "findFileRevisionById", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.id = ?1"),
		@NamedQuery(name = "findFileRevisionByPrimaryKey", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.id = ?1"),
		@NamedQuery(name = "findFileRevisionByReason", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.reason = ?1"),
		@NamedQuery(name = "findFileRevisionByRevision", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.revision = ?1"),
		@NamedQuery(name = "findFileRevisionByRowkey", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.rowkey = ?1"),
		@NamedQuery(name = "findFileRevisionBySize", query = "select myFileRevision from FileRevision myFileRevision where myFileRevision.size = ?1") })
@Table(catalog = "sow", name = "file_revision")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "FileRevision")
public class FileRevision implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "SIZE", precision = 12, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	BigDecimal size;
	/**
	 */

	@Column(name = "ROWKEY", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer rowkey;
	/**
	 */

	@Column(name = "REVISION", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer revision;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar createdDate;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "APPROVED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar approvedDate;
	/**
	 */

	@Column(name = "REASON", columnDefinition = "TEXT")
	@Basic(fetch = FetchType.EAGER)
	@Lob
	@XmlElement
	String reason;
	/**
	 */

	@Column(name = "APPROVAL_STATUS", length = 3)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String approvalStatus;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "CREATED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User userByCreatedBy;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "APPROVED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User userByApprovedBy;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "FILE_ID", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	File file;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setSize(BigDecimal size) {
		this.size = size;
	}

	/**
	 */
	public BigDecimal getSize() {
		return this.size;
	}

	/**
	 */
	public void setRowkey(Integer rowkey) {
		this.rowkey = rowkey;
	}

	/**
	 */
	public Integer getRowkey() {
		return this.rowkey;
	}

	/**
	 */
	public void setRevision(Integer revision) {
		this.revision = revision;
	}

	/**
	 */
	public Integer getRevision() {
		return this.revision;
	}

	/**
	 */
	public void setCreatedDate(Calendar createdDate) {
		this.createdDate = createdDate;
	}

	/**
	 */
	public Calendar getCreatedDate() {
		return this.createdDate;
	}

	/**
	 */
	public void setApprovedDate(Calendar approvedDate) {
		this.approvedDate = approvedDate;
	}

	/**
	 */
	public Calendar getApprovedDate() {
		return this.approvedDate;
	}

	/**
	 */
	public void setReason(String reason) {
		this.reason = reason;
	}

	/**
	 */
	public String getReason() {
		return this.reason;
	}

	/**
	 */
	public void setApprovalStatus(String approvalStatus) {
		this.approvalStatus = approvalStatus;
	}

	/**
	 */
	public String getApprovalStatus() {
		return this.approvalStatus;
	}

	/**
	 */
	public void setUserByCreatedBy(User userByCreatedBy) {
		this.userByCreatedBy = userByCreatedBy;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByCreatedBy() {
		return userByCreatedBy;
	}

	/**
	 */
	public void setUserByApprovedBy(User userByApprovedBy) {
		this.userByApprovedBy = userByApprovedBy;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByApprovedBy() {
		return userByApprovedBy;
	}

	/**
	 */
	public void setFile(File file) {
		this.file = file;
	}

	/**
	 */
	@JsonIgnore
	public File getFile() {
		return file;
	}

	/**
	 */
	public FileRevision() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(FileRevision that) {
		setId(that.getId());
		setSize(that.getSize());
		setRowkey(that.getRowkey());
		setRevision(that.getRevision());
		setCreatedDate(that.getCreatedDate());
		setApprovedDate(that.getApprovedDate());
		setReason(that.getReason());
		setApprovalStatus(that.getApprovalStatus());
		setUserByCreatedBy(that.getUserByCreatedBy());
		setUserByApprovedBy(that.getUserByApprovedBy());
		setFile(that.getFile());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("size=[").append(size).append("] ");
		buffer.append("rowkey=[").append(rowkey).append("] ");
		buffer.append("revision=[").append(revision).append("] ");
		buffer.append("createdDate=[").append(createdDate).append("] ");
		buffer.append("approvedDate=[").append(approvedDate).append("] ");
		buffer.append("reason=[").append(reason).append("] ");
		buffer.append("approvalStatus=[").append(approvalStatus).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof FileRevision))
			return false;
		FileRevision equalCheck = (FileRevision) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
